package com.wm.wmim.server.service.wsmessage;


import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.wm.wmim.server.dto.bo.WsMessageBO;
import com.wm.wmim.server.enums.WsMessageTypeEnum;
import com.wm.wmim.server.dto.bo.BaseMessageBody;

/**
 * @author weiming
 * @date 2024/8/28 23:07
 * @description
 */
public abstract class AbstractWebSocketMessageHandleService<Req extends BaseMessageBody, Resp extends WsMessageBO>{


    abstract protected Resp process(Req messageReqBody);

    abstract protected WsMessageTypeEnum getMessageType();

    private Class<Req> reqClass = currentReqClass();
    private Class<Resp> respClass = currentRespClass();

    public Class<Req> getReqClass() {
        return reqClass;
    }

    public Class<Resp> getRespClass() {
        return respClass;
    }

    private Class<Req> currentReqClass() {
        return (Class<Req>) ReflectionKit.getSuperClassGenericType(getClass(), 0);
    }

    private Class<Resp> currentRespClass() {
        return (Class<Resp>) ReflectionKit.getSuperClassGenericType(getClass(), 1);
    }

}
